﻿using System;
using System.Globalization;
using Microsoft.Xna.Framework;

namespace XTengine.ComponentModel
{
    public class BoundingSphereConverter : TypeConverter<BoundingSphere>
    {
        public override BoundingSphere ConvertFrom(string value)
        {
            string[] splits = value.Split(',');

            if (splits.Length < 4)
                return default(BoundingSphere);

            CultureInfo eng = new CultureInfo("en-US");

            BoundingSphere result = new BoundingSphere();
            result.Center.X = Single.Parse(splits[0], eng);
            result.Center.Y = Single.Parse(splits[1], eng);
            result.Center.Z = Single.Parse(splits[2], eng);

            result.Radius = Single.Parse(splits[3], eng);

            return result;
        }

        public override string ConvertTo(BoundingSphere value)
        {
            return value.Center.X + "," + value.Center.Y + "," + value.Center.Z + "," + value.Radius;
        }
    }
}